package com.youhome.wechat.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket demoApi() {
        ParameterBuilder parameterBuilder = new ParameterBuilder();

        parameterBuilder
                .name("Authorization")
                .description("在授权中输入身份验证令牌 格式：Bearer eyJhbGciOiJ.....")
                .modelRef(new ModelRef("string"))
                .parameterType("header")
                .required(false)
                .build();

        List<Parameter> parameters = new ArrayList<>();
        parameters.add(parameterBuilder.build());

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(getApiInfo())
                .useDefaultResponseMessages(false)
                .globalOperationParameters(parameters)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.youhome.wechat.controller")).build();
    }

    protected ApiInfo getApiInfo() {
        return new ApiInfo("WeChat Service Api",
                "WeChat Service",
                "1.0.0",
                "",
                new Contact("mf-data", "", ""),
                "",
                "",
                new ArrayList<>()
        );
    }
}